package com.xxxx.portal.config;


import com.xxxx.portal.interceptor.PortalInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

   /* @Autowired
    private PortalInterceptor portalInterceptor;*/
    @Bean
    public PortalInterceptor getPortalInterceptor(){
        return new PortalInterceptor();
    }

    /*
    addPathPatterns  添加拦截的资源
    excludePathPatterns  放行的资源
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getPortalInterceptor())
                .addPathPatterns("/cart/list")
                .excludePathPatterns(
                        "/cart/getCartList",
                        "/static/**",
                        "/css/**",
                        "/images/**",
                        "/js/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");

    }
}
